package com.learn.spring.ioc.way.proxy.cglib;
import com.learn.spring.ioc.way.proxy.jdk.dynamicProxy.Animal;
import net.sf.cglib.core.DebuggingClassWriter;
        import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

public class CglibProxy {
    public static void main(String[] args) {
        System.setProperty(DebuggingClassWriter.DEBUG_LOCATION_PROPERTY, "D:\\project\\learn-spring\\learn-spring\\src\\main\\resources");
//        Enhancer enhancer = new Enhancer();
//        enhancer.setSuperclass(Cat.class);
//        enhancer.setCallback(new MyMethodIntercepter());
//        Cat cat = (Cat) enhancer.create();
//        cat.eat();
//        cat.run();
//        cat.sleep();


        Enhancer enhancer = new Enhancer();
        enhancer.setSuperclass(Cat.class);
        enhancer.setCallback((MethodInterceptor) (obj, method, args1, proxy) -> {
            System.out.println("enhancer" + method.getName());
            Object result = proxy.invokeSuper(obj, args1);
            return result;
        });
        Cat catProxy = (Cat) enhancer.create();
        catProxy.eat();
        catProxy.run();
        catProxy.sleep();
    }
}
